package org.eliza.base.collectionsx

import kotlin.random.Random

class Arrayx {
    fun method() {
        println("=====method=====")
        val aChar: String = "abcdefg"
        println("str.plus a                   :${aChar.plus("a")}")
        println("str.get 0                    :${aChar.get(0)}")
        println("str.subSequence 0..2         :${aChar.subSequence(0..2)}")
        println("str.compareTo a              :${aChar.compareTo("a")}")
        println("str.equals a                 :${aChar.equals("a")}")
        println("str.length                   :${aChar.length}")
        println("str.rangeUntil a             :${aChar.rangeUntil("abcdefg")}")
        println("str.rangeUntil a             :${aChar.rangeUntil("a")}")
        println("str.rangeTo a                :${aChar.rangeTo("a")}")
        println("str.codePointCount a         :${aChar.codePointCount(1, aChar.length)}")

        println("str.random a                 :${aChar.random()}")
        println("str.randomOrNull a           :${aChar.randomOrNull(Random.Default)}")
        println("str.toCharArray            :${aChar.toCharArray()}")
        println("str.toCharArray 0..3           :${aChar.toCharArray(0, 3).joinToString()}")
        println(
            "str.toCharArray a           :${
                aChar.toCharArray(CharArray(aChar.length), 0, 1, aChar.length).joinToString()
            }"
        )
    }

    fun asParam() {
        var ff = fun(arr: Array<Int>) {
            arr.plus(1)
        }
        var of = arrayOf(1, 2, 3)
        println("arrayOf: ${of}:${of.joinToString()}")
        ff(of)
        println("arrayOf: ${of}:${of.joinToString()}")

        val toMutableList = of.toMutableList()
        var add = fun(arr: MutableList<Int>) {
            arr.plus(1)
            arr.add(10)
        }
        println("toMutableList:  ${toMutableList.joinToString()}")
        add(toMutableList)
        println("toMutableList:  ${toMutableList.joinToString()}")


    }
}

private  fun main() {
    val arrayx = Arrayx()
    arrayx.method()
    arrayx.asParam()
}